﻿using System.Collections.Generic;
using Utilities.StringLib;

namespace Utilities.RefineKeyword
{
    public class RefineKeywordList
    {
        /// <summary>
        /// Standardize the list of keywords and remove duplicated keywords
        /// </summary>
        /// <param name="KeywordsList">List of original keywords</param>
        /// <returns>List of refined keywords</returns>
        public static List<string> Refine(List<string> KeywordsList)
        {
            HashSet<string> tempHS = new HashSet<string>();
                        
            for (int i = 0; i < KeywordsList.Count; i++)
            {
                KeywordsList[i] = ProcessString.StripDiacritics(KeywordsList[i]);
                KeywordsList[i] = KeywordsList[i].ToUpper();
                tempHS.Add(KeywordsList[i]);
            }

            foreach (string meta in KeywordsList)
            {
                string tempNoSpace = meta.Replace(" ", string.Empty);
                // after remove whitespace, if this string is still the same then this is not complex word.
                if (tempNoSpace.Equals(meta) == false)
                {
                    tempHS.Remove(tempNoSpace);
                }
            }

            return new List<string>(tempHS);
        }
    }
}
